package com.dap.param;

import com.dap.utils.DeepFieldCopy;
import org.springframework.util.StringUtils;

/**
 * @author wangmin
 * @discription
 * @created 2020-04-10 9:56
 */
public abstract class CommonServiceContext {
    private static final ThreadLocal<ControlData> ctrlDataThreadLocal = new ThreadLocal<>();
    public static ControlData getCtrlData() {
        return ctrlDataThreadLocal.get();
    }
    public static void setCtrlData(ControlData value) {
        if (null != value) {
            ctrlDataThreadLocal.set(DeepFieldCopy.transform(value, ControlData.class));
        }
    }
    public static void removeCtrlData() {
        ctrlDataThreadLocal.remove();
    }


    private static final ThreadLocal<String> groupNameThreadLocal = new ThreadLocal<>();
    public static String getGroupName() {
        return groupNameThreadLocal.get();
    }
    public static void setGroupName(String value) {
        if (!StringUtils.isEmpty(value)) {
            groupNameThreadLocal.set(value);
        }
    }
    public static void removeGroupName() {
        groupNameThreadLocal.remove();
    }


    private static final ThreadLocal<Boolean> isFrontRequestThreadLocal = new ThreadLocal<>();
    public static boolean getIsFrontRequest() {
        Boolean value = isFrontRequestThreadLocal.get();
        return value != null && value;
    }
    public static void setIsFrontRequest(boolean value) {
        isFrontRequestThreadLocal.set(value);
    }
    public static void removeIsFrontRequest() {
        isFrontRequestThreadLocal.remove();
    }
}
